package com.cskaoyan.shopping.service.impl;
/*
 * @Auther:王贲
 * @Date:2022/9/21
 * @Description:
 * @VERSON:1.8
 */

import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContentItem;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dal.persistence.PanelMapper;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.service.IHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
public class IMarketServiceImpl implements IHomeService {

    @Autowired
    ContentConverter converter;

    @Autowired
    PanelMapper panelMapper;

    @Autowired
    PanelContentMapper panelContentMapper;


    @Override
    public Set<PanelDto> homepage() {
        Example example = new Example(Panel.class);
        example.createCriteria().andEqualTo("position", 0);
        List<Panel> panels = panelMapper.selectByExample(example);
        List<PanelContentItem> panelContentItems = null;
        HashSet<PanelDto> set = new HashSet<>();
        for (Panel panel : panels) {
            Integer panelId = panel.getId();
            panelContentItems = panelContentMapper.selectPanelContentAndProductWithPanelId(panelId);
            panel.setPanelContentItems(panelContentItems);
            PanelDto panelDto = converter.panel2Dto(panel);
            set.add(panelDto);
        }
        return set;
    }
}
